Skip to content

Remove conflicts recorded before a shift is discarded - #875

Merged
ydah merged 1 commit into
masterfrom
fix/discard-resolved-shift-conflicts
Nov 14, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/discard-resolved-shift-conflicts

Conversation

@ydah

@ydah ydah commented Nov 14, 2026

Copy link
Copy Markdown
Member

A shift can first conflict with a reduction whose precedence does not resolve the conflict, then be discarded by a later reduction. compute_shift_reduce_conflicts keeps the earlier conflict, so %expect validation and reports can include a shift that is no longer selected.

After resolving precedence for a state, remove shift/reduce conflicts whose shift was discarded. This makes the reported conflicts reflect the remaining actions, as in Bison's post-resolution checks (https://github.com/akimd/bison/blob/v3.8.2/src/conflicts.c#L354-L364).

For example:

%expect 0
%nonassoc 'b'
%%
start: 'a' empty 'b' 'x' | direct 'b' 'y'
     | 'a' 'b' 'z' | 'a' empty 'c';
empty: %empty;
direct: 'a' %prec 'b';

Both LALR and IELR generation previously failed with shift/reduce conflicts: 1 found, 0 expected. They now succeed, matching Bison 3.8.2. The generated parser still accepts ac and rejects abx, aby, and abz through the nonassociative error.

States that become conflict-free can also use the existing default-reduction selection. Add regression coverage for precedence, left associativity, nonassociativity, and unresolved conflicts on other tokens or with equal precedence.

@ydah
ydah merged commit 970b304 into master Nov 14, 2026
45 checks passed
@ydah
ydah deleted the fix/discard-resolved-shift-conflicts branch November 14, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant